using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UMC.Data;

namespace UMC.WorkFlow
{
    /// <summary>
    /// 回滚引导线，从一个结点回滚到另一个结点
    /// 功能：主要完成跨层次驳回;
    /// </summary>
    [UIDesign(Name = "驳回方向线", Explain = "引擎默认驳回到结束点，可以使用指定驳回到节点")]
    public class InduceLine : UMC.Data.IJSONType
    {
        [Design(Caption = "描述")]
        public String Text { get; set; }
        /// <summary>
        /// 进入的工作点名字
        /// </summary> 
        public string ToId { get; set; }
        /// <summary>
        /// 出入的工作点名字
        /// </summary>
        public string FromId { get; set; }
        /// <summary>
        /// 矢量的工作状态
        /// </summary>
        public virtual UMC.WorkFlow.CommandType Status
        {
            get { return UMC.WorkFlow.CommandType.Reject; }
        }
        /// <summary>
        /// 在矢量唯一标志
        /// </summary>
        public string Id { get; set; }
        protected virtual string JSONName()
        {
            return this.GetType().Name;
        }
        public virtual Func<object> GetInstance(string prototypeName)
        {
            return () => String.Empty;
            //throw new NotImplementedException();
        }

        public virtual void Read(string key, object value)
        {
            switch (key)
            {
                case "Id":
                    this.Id = value as string;
                    break;
                case "FromId":
                    this.FromId = value as string;
                    break;
                case "ToId":
                    this.ToId = value as string;
                    break;
                case "Text":
                    this.Text = value as string;
                    break;
            }
        }
        protected virtual void WriteProperty(TextWriter writer)
        {
            writer.Write(',');
            JSON.Serialize("Id", this.Id, writer);
            writer.Write(',');
            JSON.Serialize("FromId", this.FromId, writer);
            writer.Write(',');
            JSON.Serialize("ToId", this.ToId, writer);
            writer.Write(',');
            JSON.Serialize("Text", this.Text, writer);
            // writer.Write(',');
            // JSON.Serialize("Status", this.Status, writer);
        }

        public void Write(TextWriter writer)
        {
            writer.Write('{');
            JSON.Serialize(JSON.Constructor, JSONName(), writer);
            WriteProperty(writer);
            writer.Write('}');
        }
    }
}
